package com.seari.utils;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.seari.pojo.Page;

@SuppressWarnings("rawtypes")
public class IData extends HashMap implements Serializable {

	private Page page;// 分页对象

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static IData getInstance() {
		return new IData();
	}

	@SuppressWarnings("unchecked")
	public static IData getInstance(HttpServletRequest request) {
		Page page = new Page();
		IData data = new IData();
		Enumeration<String> names = request.getParameterNames();
		String key = "";
		String value = "";
		while (names.hasMoreElements()) {
			key = names.nextElement();
			value = request.getParameter(key).trim();
			if (key.equals("page"))
				page.setCurrentPage(Integer.valueOf(value));
			if (key.equals("size"))
				page.setShowCount(Integer.valueOf(value));
			data.put(key, value);
		}
		data.setPage(page);
		return data;
	}

	public String getString(String key) {
		return (String) this.get(key);
	}

}
